package com.lishe.lishe.lishe.module.excitation.activity;

import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.lishe.base.viewpager.MZBannerView;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.base.common.config.Constants;
import com.lishe.lishe.lishe.module.excitation.adapter.PictureViewerAdapter;
import com.lishe.lishe.lishe.module.excitation.bean.DianzanImgObject;

import java.util.ArrayList;

/**
 * 标    题：图片浏览器
 * 功能描述：
 * 作    者：zouxx
 * 创建时间：2018/8/9.
 */

public class PictureViewerActivity extends BaseActivity {

    private MZBannerView mzBannerView;
    private ArrayList<DianzanImgObject> imgUrls;
    private ArrayList<String> imgList = new ArrayList<>();
    private int postion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_picture_viewer);
        if (getIntent() != null) {
            imgUrls = (ArrayList<DianzanImgObject>) getIntent().getSerializableExtra(Constants.PICTURE_VIEWER_IMAGES);
            ArrayList<String> lists = getIntent().getStringArrayListExtra(Constants.PICTURE_VIEWER_IMAGES);
            if (imgUrls != null && imgUrls.size() > 0) {
                for (int i = 0; i < imgUrls.size(); i++) {
                    imgList.add(imgUrls.get(i).getImgUrl());
                }
            } else if (lists != null && lists.size() > 0) {
                imgList.addAll(lists);
            }
            postion = getIntent().getIntExtra(Constants.PICTURE_VIEWER_POSITION, 0);
        }
        mzBannerView = findViewById(R.id.banner_picture);
        mzBannerView.setIndicatorPosition(postion);
        PictureViewerAdapter pictureViewerAdapter = new PictureViewerAdapter(v -> finish());
        mzBannerView.setPages(imgList, () -> pictureViewerAdapter);
        mzBannerView.setIndicatorVisible(true);
    }
}
